package com.RiverScoop;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;

import com.RiverScoop.*;

public class RegisterInsert {
	private static final String drivername="com.mysql.cj.jdbc.Driver";
	private static final String url="jdbc:mysql://localhost:3306/river_scoop?useUnicode=true&serverTimezone=GMT&characterEncoding=UTF-8";
	private static final String user="root";
	private static final String pwd="root";
	static {
		try {
			Class.forName(drivername);

		} catch (ClassNotFoundException e) {
			// TODO: handle exception
		}
	}

	public static Connection getConnection() {
		Connection conn = null;
		try {
			conn = DriverManager.getConnection(url, user, pwd);

		} catch (Exception e) {
			// TODO: handle exception
		}
		return conn;

	}

	public boolean updateEmp(emp emp) {
		Connection conn = getConnection();
		String sql = "INSERT INTO login VALUES(?,?,?,?)";
		PreparedStatement pst = null;
		try {
			pst = conn.prepareStatement(sql);
			pst.setInt(1, emp.getLoginNo());
			pst.setString(2, emp.getAccount());
			pst.setString(3, emp.getPwd());
			pst.setString(4, emp.getPhone());
			int add = pst.executeUpdate();
			if (add>0) {
				return true;
			}else {
				return false;
				
			}

		} catch (SQLException e) {
			// TODO: handle exception
		}

		finally {
			try {
				if (pst != null) {
					pst.close();
				}
				if (conn != null) {
					conn.close();
				}
			} catch (Exception e2) {
				// TODO: handle exception
			}
		}
		return false;
		
	}
}
